package ils.services;

import ils.domain.acquisition.model.Delivery;
import ils.domain.acquisition.model.DeliveryFactory;
import ils.domain.acquisition.model.Order;
import ils.domain.acquisition.model.OrderFactory;
import ils.domain.acquisition.model.Seller;
import ils.domain.acquisition.model.SellerFactory;
import ils.web.model.WDelivery;
import ils.web.model.WOrder;

import java.util.Date;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

public class AquisitionServiceImpl implements AquisitionService
{
    private OrderFactory orderFactory;
    private SellerFactory sellerFactory;
    private DeliveryFactory deliveryFactory;
    private AquisitionCommon aquisitionCommon;
    @Override
    @Transactional
    public void placeOrder(WOrder order)
    {
        Seller seller = sellerFactory.getSeller(order.getSellerId());
        order.setSeller(seller);
        orderFactory.createOrder(order);
    }
    @Override
    @Transactional
    public List<WOrder> getUnsatisfiedOrders() 
    {
        List<Order> orders = orderFactory.getOpenOrders();
        return aquisitionCommon.convertOrders(orders);
    }
    @Override
    @Transactional
    public void recordDelivery(WDelivery delivery)
    {
        
        deliveryFactory.createDelivery(delivery);
    }
    @Override
    public List<WDelivery> getDeliveriesFor(int sellerId, Date from, Date to)
    {
        List<Delivery> deliveries = deliveryFactory.getDeliveriesFor(sellerId, from, to);
        return aquisitionCommon.convertDeliveries(deliveries);
        
    }
    public void setOrderFactory(OrderFactory orderFactory)
    {
        this.orderFactory = orderFactory;
    }
    public void setSellerFactory(SellerFactory sellerFactory)
    {
        this.sellerFactory = sellerFactory;
    }
    public void setDeliveryFactory(DeliveryFactory deliveryFactory)
    {
        this.deliveryFactory = deliveryFactory;
    }
    public void setAquisitionCommon(AquisitionCommon aquisitionCommon)
    {
        this.aquisitionCommon = aquisitionCommon;
    }

}
